package ink.xiaobaibai.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ink.xiaobaibai.common.UriMappingRoleName;
import ink.xiaobaibai.common.UserIdRoleNameMapping;
import ink.xiaobaibai.entity.AdminUserRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xiaobaibai
 * @since 2021-05-11
 */
public interface AdminUserRoleDao extends BaseMapper<AdminUserRole> {

    public List<UserIdRoleNameMapping> getRoleByUserIds(@Param("userIds") List<Integer> userIds);

    @Select("SELECT r.`role_name` FROM admin_role r left JOIN admin_user_role ur ON r.`id`=ur.`role_id` WHERE ur.`user_id`=#{userId}")
    public List<String> getRoleByUserId(@Param("userId") Integer userId);

    @Select("SELECT c.resources_uri,ar.role_name FROM admin_role ar\n" +
            " LEFT JOIN (SELECT r.resources_uri,rr.role_id FROM admin_resources r LEFT JOIN admin_role_resources rr ON r.`id`=rr.`resources_id`) c\n" +
            " ON c.role_id=ar.id")
    public List<UriMappingRoleName> getUriMappingRoleName();

}
